﻿using System.Web.Http;
using GC_MU.Site.Api.Attributes;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace GC_MU.Site
{
	public static class WebApiConfig
	{
		public static void Register(HttpConfiguration config)
		{
			var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
			json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
			json.SerializerSettings.Formatting = Formatting.Indented;
			config.Formatters.Add(json);
			config.MapHttpAttributeRoutes();

			config.Routes.MapHttpRoute(
				"RpcStyleApi",
				"api/{controller}/{action}/{id}",
				new { ext = "json", id = RouteParameter.Optional });

			config.Routes.MapHttpRoute(
				"DefaultApi",
				"api/{controller}/{id}",
				new { ext = "json", id = RouteParameter.Optional });

			config.Filters.Add(new NotImplExceptionFilterAttribute());
			config.Filters.Add(new ValidationActionFilterAttribute());
		}
	}
}
